import java.util.Random;
import java.util.Scanner;

public class Text {
    public static void main1(String[] args) {
        //判断一个数字是奇数还是偶数
        int a = 80;
        if(a % 2 == 0){
            System.out.println(a+"是偶数！");
        }else{
            System.out.println(a+"是奇数");
        }
    }

    public static void main2(String[] args) {
        //判断一个数字是正数，负数，还是零
        int b=-89;
        if (b > 0) {
            System.out.println(b+"是正数");
        } else if (b < 0){
            System.out.println(b+"是负数");
        } else {
            System.out.println(b+"为零");
        }

    }

    public static void main3(String[] args) {
        int year=1999;
        if(year % 100 ==0){
            if(year % 400 ==0){
                System.out.println(year+"是闰年");
            }else {
                System.out.println(year + "不是闰年");
            }
        }else{
            if(year % 4 ==0){
                System.out.println(year+"是闰年");
            }else{
                System.out.println(year + "不是闰年");
            }
        }
    }

    public static void main4(String[] args) {
        int year=1996;
        if((year % 400 == 0) || (year % 4 == 0) && (year % 100 != 0)){
            System.out.println(year+"是闰年");
        }else{
            System.out.println(year+"不是闰年");
        }
    }

    public static void main5(String[] args) {
        short a=5;
        switch(a){
            case 1:
                System.out.println("星期一");
                break;
            case 2:
                System.out.println("星期二");
                break;
            case 3:
                System.out.println("星期三");
                break;
            case 4:
                System.out.println("星期四");
                break;
            case 5:
                System.out.println("星期五");
                break;
            case 6:
                System.out.println("星期六");
                break;
            case 7:
                System.out.println("星期天");
                break;
            default:
                System.out.println("输入有误！");
                break;
        }
    }

    public static void main6(String[] args) {
        int i=1;
        while(i<=10){
            System.out.println(i);
            i++;
        }
    }

    public static void main7(String[] args) {
        int i = 1;
        int sum = 0;
        while(i <= 100){
            sum += i;
            i++;
        }
        System.out.println(sum);
    }

    public static void main8(String[] args) {
        int num = 1;
        int ret = 1;
        while(num <= 5){
            ret *= num;
            num++;
        }
        System.out.println(ret);
    }

    public static void main9(String[] args) {
        int num = 1;
        int sum = 0;
        int ret = 1;
        while(num <=5){
            ret *= num;
            sum += ret;
            num++;
        }
        System.out.println(sum);
    }

    public static void main10(String[] args) {
        int a = 10;
        System.out.println(a);
        System.out.print(a);
        System.out.printf("%d\n",a);
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入姓名：");
        String name = sc.nextLine();
        System.out.println("请输入年龄：");
        int age = sc.nextInt();
        System.out.println("请输入工资：");
        Double salary = sc.nextDouble();
        System.out.printf("%s %d %f",name ,age, salary);
    }

    public static void main11(String[] args) {
        double sum = 0l;
        int count = 0;
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextDouble()){
            double num = sc.nextDouble();
            sum += num;
            count++;
        }
        System.out.println("平均数为"+(sum/count));
    }

    public static void main12(String[] args) {
        Scanner sc = new Scanner(System.in);
        Random random = new Random();
        int toGuess = random.nextInt(100);
        while(true){
            System.out.println("请输入猜测的数字");
            int num = sc.nextInt();
            if(num > toGuess){
                System.out.println("猜大了！");
            }else if(num < toGuess){
                System.out.println("猜小了！");
            }else{
                System.out.println("猜对了！！！");
                break;
            }
        }
        sc.close();
    }

    //求 1 ~ 100 以内的素数
    public static void main13(String[] args) {

        int i = 0;
        int j = 0;
        for (i = 2; i <= 100; i++) {
            for (j = 2; j*j <= i; j++) {
                if(i % j == 0){
                    break;
                }
            }
            if(j * j > i){
                System.out.println(i);
            }
        }
    }
    //还可以：
    public static void main131(String[] args) {
        int i = 0;
        int j = 0;
        for (i = 2; i < 100; i++) {
            for (j = 2; j <= Math.sqrt(i); j++) {
                if(i % j == 0){
                    break;
                }
            }
            if(j > Math.sqrt(i)){
                System.out.println(i);
            }
        }
    }

    //编写程序数一下 1到 100 的所有整数中出现多少个数字9
    public static void main14(String[] args) {
        int i = 0;
        int count = 0;
        for (i = 1; i <100; i++) {
            if(i % 10 == 9){
                count++;
            }
            //下面的式子反而能求任意整数的十位数是否为9，并不局限于100以内
            if((i / 10) % 10 == 9){
                count++;
            }
        }
        System.out.println(count);
    }
    //修改
    public static void main141(String[] args) {
        int i = 0 ;
        int count = 0;
        for (i = 1; i <100 ; i++) {
            if(i % 10 == 9){
                count++;
            }
            //这是针对100以内的数字而言，超过了就不对了
            if(i /10 == 9){
                count++;
            }
        }
        System.out.println(count);
    }
    //如果题目这样子说
    //求 1 ~ 100 之间所有整数中，出现过9的个数
    public static void main142(String[] args) {
        int i = 0;
        int count = 0;
        for (i = 0; i < 100; i++) {
            if(i % 10 == 9){
                count++;
            }else if(i / 10 == 9){
                count++;
            }
        }
        System.out.println(count);
    }

    public static void main15(String[] args) {
        int year = 0;
        int count = 0;
        for (year = 1000; year <= 2000; year++) {
            if((year % 400 == 0)||(year % 100 != 0 && year % 4 == 0)){
                System.out.println(year);
                count++;
            }
        }
        System.out.println(count);
    }

    public static void main16(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个数，判断是否为素数：");
        while(sc.hasNextInt()){
            int num = sc.nextInt();
            int i = 0;
            for (i = 2; i*i <= num; i++) {
                if(num % i == 0){
                    break;
                }
            }
            if(i * i > num && num != 1) {
                System.out.println("是素数");
            }else{
                System.out.println("不是素数");
            }
        }
    }

    //二进制中 1 的个数
    public static void main17(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个数：");
        while(sc.hasNextInt()){
            int num = sc.nextInt();
            int i = 0;
            int count = 0;
            for (i = 0; i <= 31; i++) {
                if(((num >> i) & 1) == 1){
                    count++;
                }
            }
            System.out.println(count);
        }
    }
    //方法二：正整数能有多少个1就循环几次，但负整数依旧得把所有位循环一次
    public static void main171(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count = 0;
        while(n != 0){
            if((n & 1)==1){
                count++;
            }
            n >>>= 1;
        }
        System.out.println(count);
    }
    //方法三：利用 n & (n-1)
    //所有整数都可以有多少个1就循环多少次，更高效
    public static void main172(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count = 0;
        while(n != 0){
            n = n & (n-1);
            count++;
        }
        System.out.println(count);
    }

    //辗转相除法求最大公约数
    public static void main18(String[] args) {
        Scanner sc = new Scanner(System.in);
        int m = sc.nextInt();
        int n = sc.nextInt();
        int k = m % n;
        while(k != 0 ){
            m = n;
            n = k;
            k = m % n;
        }
        System.out.println(n);
    }

    //九九乘法表
    public static void main19(String[] args) {
        int i = 0;
        int j = 0;
        for (i = 1; i < 10; i++) {
            for (j = 1; j <= i; j++) {
                System.out.print(i+" * "+j+" = "+i*j+"   ");
            }
            System.out.println();
        }
    }

    //0 ~ 999 之间的水仙花数
    public static void main20(String[] args) {
        int i = 0;

        //每一次都需要计算相应位数，有点繁琐
        for (i = 0; i <= 999; i++) {
            int count = 0;
            //计算位数
            int temp = i;
            while(temp != 0){
                count++;
                temp /= 10;

            }
            temp = i;
            //计算水仙花数
            int sum = 0;
            while(temp != 0){
                sum += Math.pow(temp % 10 ,count);
                temp /= 10;
            }
            if(i == sum){
                System.out.print(i+" ");
            }
        }
    }

    //打印二进制的奇数位与偶数位
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int i = 0;
        System.out.println("偶数位:");
        for (i = 31; i >= 1; i-=2) {
            System.out.print(((num>>>i) & 1)+" ");
        }
        System.out.println();
        System.out.println("奇数位:");
        for (i = 30; i >= 0; i-=2) {
            System.out.print(((num>>>i) & 1)+" ");
        }
    }

}

